<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">

<head>
	<th:block th:include="include :: header('文章列表')" />
	<th:block th:include="include :: layout-latest-css" />
	<th:block th:include="include :: ztree-css" />
</head>

<body class="gray-bg">
	<div class="ui-layout-west">
		<div class="box box-main">
			<div class="box-header">
				<div class="box-title">
					<i class="fa fa-sitemap"></i> 栏目
				</div>
				<div class="box-tools pull-right">
					<a type="button" class="btn btn-box-tool" href="#" onclick="category()" title="栏目"><i
							class="fa fa-edit"></i></a>
					<button type="button" class="btn btn-box-tool" id="btnRefresh" title="刷新"><i
							class="fa fa-refresh"></i></button>
				</div>
			</div>
			<div class="ui-layout-content">
				<div id="tree" class="ztree"></div>
			</div>
		</div>
	</div>

	<div class="ui-layout-center">
		<div class="container-div">
			<div class="row">
				<div class="col-sm-12 search-collapse">
					<form id="user-form">
						<input type="hidden" id="categoryId" name="categoryId">
						<div class="select-list">
							<ul>
								<li>
									标题：<input type="text" name="title" />
								</li>
								<li>
									状态：<select name="status" th:with="type=${@dict.getType('sys_show_hide')}">
										<option value="">所有</option>
										<option th:each="dict : ${type}" th:text="${dict.dictLabel}"
											th:value="${dict.dictValue}"></option>
									</select>
								</li>
								<li class="select-time">
									<label>创建时间： </label>
									<input type="text" class="time-input" id="startTime" placeholder="开始时间"
										name="params[beginTime]" />
									<span>-</span>
									<input type="text" class="time-input" id="endTime" placeholder="结束时间"
										name="params[endTime]" />
								</li>
								<li>
									<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
											class="fa fa-search"></i>&nbsp;搜索</a>
									<a class="btn btn-warning btn-rounded btn-sm" onclick="resetPre()"><i
											class="fa fa-refresh"></i>&nbsp;重置</a>
								</li>
							</ul>
						</div>
					</form>
				</div>

				<div class="btn-group-sm" id="toolbar" role="group">
					<a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:user:add">
						<i class="fa fa-plus"></i> 新增
					</a>
					<a class="btn btn-primary single disabled" onclick="$.operate.edit()"
						shiro:hasPermission="system:user:edit">
						<i class="fa fa-edit"></i> 修改
					</a>
					<!--        <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:user:remove">
		                <i class="fa fa-remove"></i> 删除
		            </a> -->
				</div>

				<div class="col-sm-12 select-table table-striped">
					<table id="bootstrap-table"></table>
				</div>
			</div>
		</div>
	</div>

	<th:block th:include="include :: footer" />
	<th:block th:include="include :: layout-latest-js" />
	<th:block th:include="include :: ztree-js" />
	<script th:inline="javascript">
		var prefix = ctx + "shop/cms";
		var editFlag = [[${@permission.hasPermi('shop:cms:edit')}]];
		var removeFlag = [[${@permission.hasPermi('shop:cms:remove')}]];
		var states = [[${@dict.getType('sys_show_hide')}]];
		var datas = [[${@dict.getType('shop_yes_no')}]];
		$(function () {
			var panehHidden = false;
			if ($(this).width() < 769) {
				panehHidden = true;
			}
			$('body').layout({initClosed: panehHidden, west__size: 185});
			// 回到顶部绑定
			if ($.fn.toTop !== undefined) {
				var opt = {
					win: $('.ui-layout-center'),
					doc: $('.ui-layout-center')
				};
				$('#scroll-up').toTop(opt);
			}
			queryArticleList();
			queryCategoryTree();
		});

		function queryArticleList() {
			var options = {
				url: prefix + "/article/list",
				createUrl: prefix + "/article/add",
				updateUrl: prefix + "/article/edit/{id}",
				removeUrl: prefix + "/article/remove",
				sortName: "createTime",
				sortOrder: "desc",
				modalName: "用户",
				columns: [{
					checkbox: true
				},
				{
					field: 'image',
					title: '主图',
					formatter: function (value, row, index) {
						if (value == null || value == '') {
							return '';
						}
						return "<img src='" + value + "' style='width:30px;height:30px;' target='_blank' title='点击查看' onclick='imagePreview(\"" + value + "\")'></img>";
					}
				},
				{
					field: 'title',
					title: '标题',
					align: 'center',
					formatter: function (value, row, index) {
						return $.table.tooltip(value);
					}
				},
				{
					field: 'categoryName',
					title: '所属栏目',
					align: 'center'
				},
				{
					field: 'author',
					title: '作者',
					align: 'center'
				},
				{
					field: 'visits',
					title: '浏览量',
					align: 'center'
				},
				{
					field: 'createTime',
					title: '创建时间',
					align: 'center'
				},
				{
					field: 'status',
					title: '状态',
					align: 'center',
					formatter: function(value, row, index) {
						return $.table.selectDictLabel(states, value);
					}
				},
				{
					field: 'isShow',
					title: '首页轮播',
					align: 'center',
					formatter: function(value, row, index) {
						return $.table.selectDictLabel(datas, value);
					}
				},
				{
					field: 'sort',
					title: '排序',
					align: 'center'
				},
				{
					title: '操作',
					align: 'center',
					formatter: function (value, row, index) {
						if (row.userId != 1) {
							var actions = [];
							actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.articleId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
							actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.articleId + '\')"><i class="fa fa-remove"></i>删除</a> ');
							return actions.join('');
						} else {
							return "";
						}
					}
				}]
			};
			$.table.init(options);
		}

		function queryCategoryTree() {
			var url = prefix + "/category/treeData/0";
			var options = {
				url: url,
				expandLevel: 2,
				onClick: zOnClick
			};
			$.tree.init(options);

			function zOnClick(event, treeId, treeNode) {
				$("#categoryId").val(treeNode.id);
				$.table.search();
			}
		}

		$('#btnRefresh').click(function () {
			queryCategoryTree();
		});


		/* 栏目管理 */
		function category() {
			var url = prefix + "/category";
			$.modal.openTab("栏目管理", url);
		}

		function imagePreview(url) {
			layer.photos({photos: {"data": [{"src": url}]}});
		}


	</script>
</body>

</html>